<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
    	session('ADMIN_ID',null);
    	$this->display();
    }
    
    public function login(){
        $data = $_POST;
        $code = 10010;
        $msg = '请输入用户名';
        if($data['user_name']){
            $msg = '请输入密码';
            if($data['password'] && $data['password'] = md5($data['password'])){
                $arr['user_name'] = $data['user_name'];
                $arr['password'] = $data['password'];
                $res = D("member")->getAdminInfo($arr);
                if($res['code'] == 1){
                    session("ADMIN_ID",$res['data']);
                    $code = 10000;
                    $msg = '登陆成功  ';
                }else{
                    $code = $res['code'];
                    $msg = $res['msg'];
                }
            }
        }
        $return_array = array(
            'code' => $code,
            'msg' => $msg,
            'data' => array(
                'url' => U('index/index')
            )
        );
        echo json_encode($return_array);
    }
    public function logout(){
        session('ADMIN_ID','');
        $this->redirect(U('Login/index'));
    }
}